import Vue from 'vue'
import Router from 'vue-router'
import home from './router/home'

Vue.use(Router)

const login = [{
  path: '/login', // 登录
  name: 'Login',
  meta: { title: '登录' },
  component: () => import('@/views/login')
}]
console.log(window)

let router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: login.concat(home).concat(
    [{
      path: '/401',
      name: 'NotFound',
      meta: { title: '404' },
      component: () => import('@/views/404')
    },
    {
      path: '*',
      name: '404',
      redirect: {
        path: '/401'
      }
    }
    ])
})

router.beforeEach((to, from, next) => {
  // window.document.title = to.meta.title;
  window.document.title = to.name
  next()
})

router.afterEach((to, from, next) => {
  window.scrollTo(0, 0) // 离开的时候回到顶部
})

export default router
